<!-- Modal -->
<div class="modal fade " id="addSaleProductModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document" style="width: 50%">
        <div class="box box-info">
            <div class="box-header with-border">
                <h3 class="box-title">在售项目信息</h3>
            </div>
            <!-- /.box-header -->
            <!-- form start -->
            <form class="form-horizontal">
                <div class="box-body">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">项目名称：</label>
                        <div class="col-sm-3">
                            <input id="addSaleProductModal_name" type="text" class="form-control"
                                   style="width: 100%;">
                            <input id="addSaleProductModal_id" type="hidden">
                        </div>
                        <label class="col-sm-3 control-label">投资者收益率（%）：</label>
                        <div class="col-sm-3">
                            <input id="addSaleProductModal_yield" type="text" class="form-control" style="width: 100%;">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">期限（年）：</label>
                        <div class="col-sm-3">
                            <input id="addSaleProductModal_timelimit" type="text" class="form-control"
                                   style="width: 100%;">
                        </div>
                        <label class="col-sm-3 control-label">规模（亿元）：</label>
                        <div class="col-sm-3">
                            <input id="addSaleProductModal_investScale" type="text" class="form-control" style="width: 100%;">
                        </div>
                    </div>

                </div>
                <!-- /.box-body -->
                <div class="box-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button id="btnSubmit" type="button" class="btn btn-primary pull-right"
                            onclick="addSaleProductModal_save()">保存
                    </button>
                </div>
                <!-- /.box-footer -->
            </form>
        </div>
    </div>
</div>

<script>


    function addSaleProductModal_init() {
        $("#addSaleProductModal_name").val("");
        $("#addSaleProductModal_id").val("");
        $("#addSaleProductModal_yield").val("");
        $("#addSaleProductModal_timelimit").val("");
        $("#addSaleProductModal_scale").val("");
    }

    function addSaleProductModal_setValue(index) {
        if(index == "-1")
            return;
        var options = $("#table1").bootstrapTable("getData");
        var row = options[index];
        $("#addSaleProductModal_name").val(row.name);
        $("#addSaleProductModal_id").val(row.id);
        $("#addSaleProductModal_yield").val(row.yield);
        $("#addSaleProductModal_timelimit").val(row.timelimit);
        $("#addSaleProductModal_investScale").val(row.investScale);

    }


    function addSaleProductModal_save() {
        var name = $("#addSaleProductModal_name").val();
        if (name == "" || undefined == name) {
            toastr['error']('请输入名称', '提示');
            return;
        }
        var yield = $("#addSaleProductModal_yield").val();
        if (yield == "" || undefined == yield) {
            toastr['error']('请输入投资者收益率', '提示');
            return;
        }
        var timelimit = $("#addSaleProductModal_timelimit").val();
        if (timelimit == "" || undefined == timelimit) {
            toastr['error']('请输入期限', '提示');
            return;
        }
        var data = {
            name: name,
            id: $("#addSaleProductModal_id").val(),
            yield: yield,
            timelimit: timelimit,
            investScale: $("#addSaleProductModal_investScale").val()
        };
        var url = "/institutionrefer/save";
        postReq(url, data, function (result) {
            if (result.success) {
                toastr['success']('操作成功', '提示');
                $("#table1").bootstrapTable("refresh");
                $("#addSaleProductModal").modal("hide");
            } else {
                toastr['error'](result.msg, '提示');
            }
        });
    }
</script>
